package cn.wowjoy.pda.android_pharmacy.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

import cn.wowjoy.pda.android_pharmacy.R;
import cn.wowjoy.pda.android_pharmacy.model.xmlEntity.inHospitalPatientInfo.InHospitalPatientBeen;

/**
 * Created by sinyo on 2017/8/3.
 */

public class LvSearchAdapter extends BaseAdapter {
    /**
     * 上下文
     */
    private Context mContext;

    /**
     * 数据源
     */
    private List<InHospitalPatientBeen> mDatas;


    /**
     * 构造函数
     *
     * @param context
     * @param datas
     */
    public LvSearchAdapter(Context context, List<InHospitalPatientBeen> datas) {
        mContext = context;
        mDatas = datas;
    }

    @Override
    public int getCount() {
        return mDatas.size();
    }

    @Override
    public Object getItem(int i) {
        return mDatas.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int position, View view, ViewGroup viewGroup) {
        ViewHolder vh = null;
        if (null == view) {
            vh = new ViewHolder();
            LayoutInflater mInflater = LayoutInflater.from(mContext);
            view = mInflater.inflate(R.layout.item_lv_search, null);
            vh.mNameTv = (TextView) view.findViewById(R.id.tv_lv_search_medicine_name);
            vh.mFormatTv = (TextView) view.findViewById(R.id.tv_lv_search_medicine_format);
//            vh.mLinearLayout= (LinearLayout) view.findViewById(R.id.ll_listview);
            vh.mImageView= (ImageView) view.findViewById(R.id.imgv_gouzi);
            view.setTag(vh);
        } else {
            vh = (ViewHolder) view.getTag();
        }
        InHospitalPatientBeen bean = (InHospitalPatientBeen) getItem(position);
        if (null != bean) {
            if(null != bean.getSFGWPB() && !"".equals(bean.getSFGWPB())){
                if(Integer.parseInt(bean.getSFGWPB()) == 1){
                    vh.mNameTv.setTextColor(mContext.getResources().getColor(R.color.red));
                }else{
                    vh.mNameTv.setTextColor(mContext.getResources().getColor(R.color.text_undanger));
                }
            }
            if(bean.isCheck()){
//                vh.mLinearLayout.setBackgroundColor(mContext.getResources().getColor(R.color.login_hint));
                vh.mImageView.setVisibility(View.VISIBLE);
            }else{
//                vh.mLinearLayout.setBackgroundColor(mContext.getResources().getColor(R.color.white));
                vh.mImageView.setVisibility(View.GONE);
            }
            vh.mNameTv.setText(bean.getZZYPMC());
            vh.mFormatTv.setText(bean.getZZYPGG());
        }
        return view;
    }


    /**
     * vh
     */
    class ViewHolder {
        /**
         * 姓名
         */
        TextView mNameTv;
        /**
         * 规格
         */
        TextView mFormatTv;
        /**
         * 图标
         */
        ImageView mImageView;

//        LinearLayout mLinearLayout;
    }
}
